<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m"  id="upload" method="post"   enctype="multipart/form-data">
			<div class="form-group">	
			<!-- 	<label class="col-sm-3 control-label">标签类型：</label>
				<div class="col-sm-8">
					<input id="tagType" name="tagType" class="form-control" type="text">
				</div> -->
				<label class="col-sm-3 control-label">标签类型：</label>
				<div class="col-sm-8">
				    <select id="tagType" name="tagType" class="form-control m-b" th:with="type=${@dict.getType('gh_label_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">入库数量：</label>
				<div class="col-sm-8">
					<input id="amount" name="amount" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">明细文件名称：</label>
				<div class="col-sm-4">
					<input id="itemFileName" class="" name="itemFileName"   type="file">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "module/depotHead"
		$("#upload").validate({
			rules:{
				tagType:{
					required:true,
				},
				amount:{
					required:true,
					isDigits:true,
				},
				remark:{
					maxlength: 255
				},
			}
		});
		
	
		
		function submitHandler() {
	        if ($.validate.form()) {
	          /*   $.operate.save(prefix + "/add", $('#form-depotHead-add').serialize()); */
	        	add();
	        }
	    }
		
		 function add() {
		    console.log("start");
		   
				var imagePath = $("#itemFileName").val();  
			    if (imagePath == "") {  
			    	alert("please upload excle file",2);
			        return false;  
			    }  
			    var prefix = ctx + "module/depotHead";
			    var strExtension = imagePath.substr(imagePath.lastIndexOf('.') + 1);  
			    if (strExtension!='xls') { 
			    	if (strExtension!='xlsx') { 
			    		if (strExtension!='png') { 
			    			alert("please upload excle that is not excle",2);  
					        return false; 
				    	}
			    	}
			    }
			    var form = new FormData(document.getElementById("upload"));
			    $.ajax({  
			        type : 'POST',  
			        url : prefix+"/add",  
			        data: form,
			        processData:false,
	                contentType:false,
			        success : function(result) {  
			        	if(result.msg=='00'){
			        		/* console.log("导入成功了") */
			        		$.operate.saveSuccess(result);
			        	}else{
			        		$.modal.alertError("错误提示："+result.msg);
			        	
			        	}
			        },  
			        error : function() {  
			        	$.modal.alertError("错误提示：上传失败，请检查网络后重试,上传文件太大");
		
			        }  
			    });
			
	     }

	</script>
</body>
</html>
